#include <REGX52.H>
#include "IIC.h"

#define PCF8591_Address_W 0x90
#define PCF8591_Address_R 0x91
#define PCF8591_Command 0x40    //Chanel 1

void PCF8591_Init()
{
    IIC_Start();
    IIC_SendByte(PCF8591_Address_W);
    IIC_ReceiveAck();
    IIC_SendByte(PCF8591_Command);
    IIC_ReceiveAck();
    IIC_Stop();
}

unsigned char PCF8591_ReadData()
{
    unsigned char Temp = 0;
    IIC_Start();
    IIC_SendByte(PCF8591_Address_R);
    IIC_ReceiveAck();
    Temp = IIC_ReceiveByte();
    IIC_SendAck(1);
    IIC_Stop();
    return Temp;
}